<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="com.shsh.safemanage.util.RequestUtil"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.shsh.safemanage.action.PostcheckReportAction"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.model.PostcheckDepartMonthCheckSummaryReport"%>
<%@page import="com.shsh.safemanage.model.PostcheckDepartMonthCheckSummaryRow"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%
{
session.removeAttribute(Constants.SESSION_POSTCHECK_DEPART_MONTH_CHECK_REPORT);

Long problemID = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_ID, (Long)null);
Long transferID = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_TRANSFER_ID, (Long)null);
	
User sessionUser = (User)session.getAttribute(Constants.SESSION_USER);
	
PostcheckReportAction reportAction = ActionCreator.createPostcheckReportAction();
UserAction userAction = ActionCreator.createUserAction();

PostCheckDao thePostcheckDao = DaoCreator.createPostCheckDao();
ProblemDao problemDao = DaoCreator.createProblemDao();
UserDao userDao = DaoCreator.createUserDao();

Problem problem = problemDao.getProblemByID(problemID);
PostcheckDepartMonthCheckSummaryReport reportTable = thePostcheckDao.getMonthCheckSummaryReportByProblemID(problemID);

session.setAttribute(Constants.SESSION_POSTCHECK_DEPART_MONTH_CHECK_REPORT, reportTable);

int year = reportTable.getYear();
int month  = reportTable.getMonth();

String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);
if(fromPage == null){
	fromPage = "user_info.jsp";
} else if(fromPage.equals("problemsTobeProcessed")){
	fromPage = "problems_tobe_processed.jsp";
} else if (fromPage.equals("yiban")) {
	fromPage = "problem_browse.jsp";
} else {
	fromPage = "user_info.jsp";
}
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 岗检汇总统计 &gt;&gt;作业部<%=month %>月岗检考核汇总表
</div>
<div class="tt">《作业部月岗检考核汇总表》</div>
<div class="content" style="">
	<div style="width:97%;margin-left: 10px;font-weight:bold;font-size:20; ">
	<span style="margin-right: 20px;float:right;">
		月份：<%=reportTable.getYear() %>年<%=reportTable.getMonth() %>月
	</span>
	</div>
	<table border="1" width="99%" style="align:center; margin-left: 6px">
	<tr>
		<td rowspan="2" style="text-align:center;width:4%;" class="td3">
		序号
		</td>
		<td rowspan="2" style="text-align:center;width:10%;" class="td3">
		岗检管理线条
		</td>
		<td rowspan="2" style="text-align:center;width:12%;" class="td3">
		作业部
		</td>
		<td rowspan="2" style="text-align:center;width:12%;" class="td3">
		装置
		</td>
		<td rowspan="2" style="text-align:center;width:6%;" class="td3">
		扣分分值
		</td>
		<td rowspan="2" style="text-align:center;width:16%;" class="td3">
		扣分原因
		</td>
		<td colspan="2" style="text-align:center;" class="td3">
		作业部反馈信息
		</td>
		<td rowspan="2" style="text-align:center;width:8%;" class="td3">
		问题流转状态
		</td>
		<td rowspan="2" style="text-align:center;width:5%;" class="td3">
		详细信息
		</td>
		<td rowspan="2" style="text-align:center;width:8%;" class="td3">
		岗检管理线条问题汇总
		</td>
	</tr>
	<tr>
		<td style="text-align:center;width:11%;"  class="td3">
		考核落实情况
		</td>
		<td style="text-align:center;width:9%;"  class="td3">
		是否整改
		</td>
	</tr>
	
	<%
	List<PostcheckDepartMonthCheckSummaryRow> rowList = reportTable.getRowList();
	for(int i = 0; i< rowList.size();i++) {
		PostcheckDepartMonthCheckSummaryRow row = rowList.get(i);
		List<Problem> problemList = row.getProblemList();
		PostCheck postcheck = row.getPostcheck();
		boolean orderDisplayed = false;
		for (Problem p : problemList) {
			String userTransferFeedbackStr = userAction.getUserTransferFeedbackStr(problemDao.getLatestProblemTransferFeedbackByProblemID(p.getId()));
			p.setUserTransferFeedbackStr(userTransferFeedbackStr);
	%>
	<tr>
		<%
		if(!orderDisplayed) {
		%>
		<td style="text-align:center;" rowspan="<%=problemList.size()%>">
			<%=(i+1) %>
		</td>
		<td style="text-align:center;" rowspan="<%=problemList.size()%>">
			<%=postcheck.getCheckName() %>
		</td>
		<%
		}
		%>
		<td style="text-align:center;">
		<%=reportTable.getDepart1Name() %>
		</td>
		<td style="text-align:center;">
		<%=p.getEquipmentName() %>
		</td>
		<td style="text-align:center;">
		<%=p.getGrade()==null?"&nbsp;":Util.formatGrade(p.getGrade()) %>
		</td>
		<td style="text-align:left;">
		<%=Util.getDisplay(p.getProblemContent(), "&nbsp;")%>
		</td>
		<td style="text-align:center;">
			<textarea id="CloseFeedback<%=p.getId() %>" name="CloseFeedback<%=p.getId() %>" rows="3"><%=Util.getDisplay(p.getCloseFeedback(), "") %></textarea>
		</td>
		<td style="text-align:center;">
			<input id="ClosedTrue<%=p.getId() %>" name="ClosedTrue<%=p.getId() %>" type="checkbox" value="true"    <%=p.getIsClosed()?"checked=\"checked\"":"" %> onclick="checkClosedTrue(<%=p.getId() %>)"/><label for="ClosedTrue<%=p.getId() %>">是</label>
			<input id="ClosedFalse<%=p.getId() %>" name="ClosedFalse<%=p.getId() %>" type="checkbox" value="false"  <%=!p.getIsClosed()?"checked=\"checked\"":"" %>onclick="checkClosedFalse(<%=p.getId() %>)" /><label for="ClosedFalse<%=p.getId() %>">否</label>
		</td>
		<td style="text-align:center;">
			<%=p.getUserTransferFeedbackStr()%>
		</td>
		<td style="text-align:center;">
			<a href="javascript:" onclick="readPostcheck(<%=p.getId()%>)">查看</a>
		</td>
		<%
		if(!orderDisplayed) {
		%>
		<td style="text-align:center;" rowspan="<%=problemList.size()%>">
			<%=problemList.size() %>
		</td>
		<%
		orderDisplayed = true;
		
		}
		
		}
		%>
	</tr>
	<%
	}
	%>
	<tr>
		<td colspan="2" style="text-align:center;"  class="td3">
		合计考核分
		</td>
		<td style="text-align:center;">
		<%=reportTable.getGradeSum()==null?"&nbsp;":Util.formatGrade(reportTable.getGradeSum()) %>
		</td>
		<td colspan="2"  style="text-align:center;"  class="td3">
		考核金额（元）：
		</td>
		<td style="text-align:center;">
		<%=Util.formatGrade(reportTable.getPenaltySum())%>
		</td>
		<td style="text-align:center;"  class="td3">
		已整改计数
		</td>
		<td style="text-align:center;" id="processedNumberTD">
		<%=Util.getDisplay(reportTable.getClosedCount(), "&nbsp;")%>
		</td>
		<td colspan="2" style="text-align:center;"  class="td3">
		问题数量
		</td>
		<td style="text-align:center;">
		<%=Util.getDisplay(reportTable.getProblemCount(), "&nbsp;")%>
		</td>
	</tr>
	<tr>
		<td class="td3" colspan="2" style="text-align:center;" >
			汇总人
		</td>
		<td style="text-align:center;">
		<%=problem.getWriteUserName() %>
		</td>
		<td class="td3" colspan="2" style="text-align:center;" >
			汇总日期
		</td>
		<td style="text-align:center;">
			<%=Util.formatDate(problem.getWriteTime()) %>
		</td>
		<td class="td3" style="text-align:center;" >
			负责人
		</td>
		<td style="text-align:center;">
		<%
			String closeUserName = null;
			if(problem.getCloseUserID() !=null ){
				User user = userDao.getUserByID(problem.getCloseUserID());
				closeUserName = user.getName();
			}
		%>
		<%=Util.getDisplay(closeUserName, "&nbsp;") %>
		<%
		%>
		</td>
		<td colspan="2" class="td3" style="text-align:center;" >
			确认日期
		</td>
		<td style="text-align:center;">
			<%=problem.getCloseTime() == null? "&nbsp;":Util.formatDate(problem.getCloseTime()) %>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="11" >
				<span style="margin-left: 30px; font-weight: bold">反馈信息：</span>
				<br />
				<div id="feedbackProcessMethodDiv">
				<%@include file="/postcheck/report/feedback_depart_month_check_method.jsp" %>
				</div>				
			</td>
	</tr>
	<tr>
		<td class="td1" height="35" colspan="11" style="padding-top:15px;padding-bottom:15px;">
			<input type="button" style="margin-left: 45%;" value="提 交" onclick="feedbackPostcheckMonthCheckReport()" />
			<input type="button" style="margin-left: 30px;" value="取 消" onclick="cancelWrite()" />
		</td>
	</tr>
	</table>
</div>
<script type="text/javascript">

function readPostcheck(problemID) {
	showDialog('readPostcheckDialog', '岗检详细情况查看', 
			'<%=request.getContextPath()%>/postcheck/read_postcheck_section.jsp?id=' + problemID, 
			750, 500);

}

function createParamJSON(){
	var paramJSON = '';
	$('textarea').each(function(){
		var paramName = "'" + this.name + "'" ;
		var str = $(this).attr('value');
		str=str.replace(/\\/g,"\\\\");
		str=str.replace(/\'/g,"\\\'");
		str=str.replace(/\"/g,"\\\"");
		str=str.replace(/\:/g,"\\\:");
		str=str.replace(/\,/g,"\\\,");
		
		var paramValue =  "'" + str + "'";
		//var paramValue =  "'" + $(this).attr('value') + "'";
		paramJSON =  paramJSON + "," + paramName + ":" + paramValue;
	});	
	
	$('input:checkbox').each(function(){
		var paramName = "'" + this.name + "'" ;
		var paramValue =  "'" + $(this).attr('checked') + "'";
		paramJSON =  paramJSON + "," + paramName + ":" + paramValue;
	});
	
	paramJSON = paramJSON.substring(1);
	paramJSON = '{' + paramJSON + '}';
	
	//alert(paramJSON);
	return paramJSON;
}

function feedbackPostcheckMonthCheckReport(){

	var processMethod = 0;
	var processRadio1 = document.getElementById('processRadio1');
	var processRadio3 = document.getElementById('processRadio3');
	if (processRadio3 != null && processRadio3.checked) {
		processMethod = 3;
	} else 	if (processRadio1 != null && processRadio1.checked) {
		processMethod = 1;
	}

	var paramJSON = createParamJSON();
	
	if ($.dialog.confirm('您确定反馈吗？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'<%=request.getContextPath()%>/postcheck/report/feedback_depart_month_check_process.jsp',
			data:{
				processMethod: processMethod,
				id: <%=problemID%>,
				transferID: <%=transferID%>,
				feedback: '',
				problemTitle: '《<%=reportTable.getDepart1Name() %><%=month %>月岗检考核汇总表》',
				paramJSON: paramJSON
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('反馈成功！', function() { loadPageSection('<%=request.getContextPath()%>/user_infor.jsp', 'mainContentDiv'); });
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	}, function(){}));
}



function checkClosedTrue(problemID) {
	var trueID = '#ClosedTrue' + problemID;
	var falseID = '#ClosedFalse' + problemID;
	if($(trueID).attr('checked') == true){
		$(falseID).attr('checked', false);
		updateProcessedNumber(1);
	} else {
		$(falseID).attr('checked', true);
		updateProcessedNumber(-1);
	}
}

function checkClosedFalse(problemID){
	var trueID = '#ClosedTrue' + problemID;
	var falseID = '#ClosedFalse' + problemID;
	if($(falseID).attr('checked') == true){
		$(trueID).attr('checked', false);
		updateProcessedNumber(-1);
	} else {
		$(trueID).attr('checked', true);
		updateProcessedNumber(1);
	}
}

function cancelWrite(){
	if ($.dialog.confirm('您确定取消反馈吗？', function(){
		loadPageSection('<%=request.getContextPath()%>/<%=fromPage%>', 'mainContentDiv');
	}, function(){}));	
}

function chooseProcessMethod(method) {
	//empty.
	//convertProblem();
}

var processedNumber = <%=Util.getDisplay(reportTable.getClosedCount(), "0")%>;
function updateProcessedNumber(num) {
	processedNumber += num;
	setElementInnerHtmlByID('processedNumberTD', processedNumber);
}
</script>
<%
}// end of page
%>